package exam.bak.beike;

import java.util.Scanner;
import java.util.Stack;

public class P2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = Integer.parseInt(scanner.nextLine());
        while (T-- > 0) {
            int n = Integer.parseInt(scanner.nextLine());
            String exp = scanner.nextLine();
            System.out.println(calc(exp));
        }
    }

    private static int calc(String exp) {
        Stack<Character> stack = new Stack<>();
        for (char c : exp.toCharArray()) {
            if (c == '(') {
                stack.push(')');
            } else {
                if (!stack.isEmpty() && stack.peek() == '(') {
                    stack.pop();
                } else {
                    stack.push(')');
                }
            }
        }
        return stack.size() / 2;
    }
}
